home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Language/OS - Multiplatform Resource Library
/
LANGUAGE OS.iso
/
pcr
/
pcr4_4.lha
/
DIST
/
boot
/
CommandLine.c
next >
Wrap
C/C++ Source or Header
|
1990-11-06
|
25KB
|
1,038 lines
/* begincopyright
Copyright (c) 1988 Xerox Corporation. All rights reserved.
Use and copying of this software and preparation of derivative works based
upon this software are permitted. Any distribution of this software or
derivative works must comply with all applicable United States export
control laws. This software is made available AS IS, and Xerox Corporation
makes no warranty about the software, its performance or its conformity to
any specification. Any person obtaining a copy of this software is requested
to send their name and post office or electronic mail address to
PCRCoordinator.pa@xerox.com, or to:
PCR Coordinator
Xerox PARC
3333 Coyote Hill Rd.
Palo Alto, CA 94304
endcopyright */
/*
* CommandLine.c
*
* PCR command line processing.
*
* Demers, November 6, 1990 11:22:42 am PST
*/
#include "xr/CommandLine.h"
#include "xr/CommandLinePrivate.h"
#include "xr/Threads.h"
#include "xr/ThreadsBackdoor.h"
#include "xr/ThreadsMsg.h"
#include "xr/UIO.h"
#include <ctype.h>
/*
* Global data
*/
struct XR_MLRep XR_globalCLLock;
#define LOCK() if( XR_currThread != NIL ) XR_MonitorEntry(&XR_globalCLLock)
#define UNLOCK() if( XR_currThread != NIL ) XR_MonitorExit(&XR_globalCLLock)
/*
* Utilities ...
*/
#define LOCKHANDLE(h) if(XR_currThread != NIL ) \
XR_MonitorEntry( &(((XR_CLHandleInner)(h))->clh_ml) )
#define UNLOCKHANDLE(h) if(XR_currThread != NIL ) \
XR_MonitorExit( &(((XR_CLHandleInner)(h))->clh_ml) )
static char *
XR_CLNew(nBytes)
unsigned nBytes;
{
char *ans;
if( XR_currThread == NIL ) {
ans = ((char *)(XR_AllocSharedSysMem(nBytes)));
} else {
ans = ((char *)(XR_calloc(nBytes, 1)));
}
return ans;
}
/*
The following proc is part of newer C libraries ...
*/
bool
strcmpcase(s1, s2)
char *s1;
char *s2;
{
char c1, c2;
for(;;) {
c1 = *s1++; c2 = *s2++;
if( c1 == 0 ) {
return ((c1 < c2) ? (-1) : 0);
}
if( c1 != c2 ) {
if( islower(c1) && (c2 == toupper(c1)) ) continue;
if( isupper(c1) && (c2 == tolower(c1)) ) continue;
return ((c1 < c2) ? (-1) : 1);
}
}
}
static bool
XR_CLStrEQ(s1, s2, caseSensitive)
char *s1;
char *s2;
bool caseSensitive;
{
return ( (caseSensitive)
? ( strcmp(s1, s2) == 0 )
: ( strcmpcase(s1, s2) == 0 ) );
}
/*
* Exported to CommandLine.h ...
*/
XR_CLProcsHandle
XR_CLCreateProcsHandle()
{
XR_CLProcsHandleInner clph;
clph = (XR_CLProcsHandleInner) XR_CLNew( sizeof *clph );
return ((XR_CLProcsHandle)(clph));
}
static XR_CLRegistrationInner
XR_CLLookupRegistrationInternal(pH, key, caseSensitive)
XR_CLProcsHandle pH;
char *key;
bool caseSensitive;
{
XR_CLProcsHandleInner clph = ((XR_CLProcsHandleInner)(pH));
XR_CLRegistrationInner clr;
for( clr = clph->clph_registrations
; (clr != NIL) && ( !XR_CLStrEQ(key, clr->clr_key,
(caseSensitive && clr->clr_caseSensitive)) )
; clr = clr->clr_next
) { }
return clr;
}
XR_CLRegistration
XR_CLRegisterProc(pH, key, caseSensitive, helpMsg, proc, replace)
XR_CLProcsHandle pH;
char *key;
bool caseSensitive;
char *helpMsg;
XR_MesaProc proc;
bool replace;
{
XR_CLRegistrationInner rOld, rNew;
if( (pH == NIL) || (proc == NIL) )
return NIL;
LOCK();
rOld = XR_CLLookupRegistrationInternal(pH, key, caseSensitive);
if( rOld == NIL ) {
rNew = ((XR_CLRegistrationInner)(XR_CLNew( sizeof *rNew )));
if( rNew != NIL ) {
rNew->clr_next = ((XR_CLProcsHandleInner)(pH))->clph_registrations;
((XR_CLProcsHandleInner)(pH))->clph_registrations = rNew;
}
} else if( replace ) {
rNew = rOld;
} else {
rNew = NIL;
}
if( rNew != NIL ) {
rNew->clr_key = key;
rNew->clr_caseSensitive = caseSensitive;
rNew->clr_helpMsg = helpMsg;
rNew->clr_proc = proc;
}
UNLOCK();
return ((XR_CLRegistration)(rNew));
}
int
XR_CLUnsafeRegisterProcs(pH, description)
XR_CLProcsHandle pH;
char **description;
{
XR_UntypedProc proc;
XR_Pointer data;
XR_MesaProc mProc;
char *help;
char *key;
XR_CLRegistration r;
char **desc;
desc = description;
while( *desc ) {
proc = *((XR_UntypedProc *)(desc)); desc++;
data = *((XR_Pointer *)(desc)); desc++;
mProc = XR_MakeMesaProc(proc, data);
if( mProc == NIL ) return (-1);
help = *((char **)(desc)); desc++;
while( *desc ) {
key = *((char **)(desc)); desc++;
r = XR_CLRegisterProc( pH, key, FALSE, help, mProc, TRUE );
if( r == NIL ) return (-2);
}
desc++;
}
}
int
XR_CLUnregister(pH, r)
XR_CLProcsHandle pH;
XR_CLRegistration r;
{
XR_CLRegistrationInner ri, prev;
if( pH == NIL ) return (-1);
LOCK();
ri = ((XR_CLProcsHandleInner)(pH))->clph_registrations;
prev = NIL;
while( ri != NIL ) {
if( ri == ((XR_CLRegistrationInner)(r)) ) {
if( prev == NIL ) {
((XR_CLProcsHandleInner)(pH))->clph_registrations
= ri->clr_next;
} else {
prev->clr_next = ri->clr_next;
}
break;
}
prev = ri;
ri = ri->clr_next;
}
UNLOCK();
return ((ri == ((XR_CLRegistrationInner)(r))) ? 0 : (-1));
}
XR_CLRegistration
XR_CLGetRegistrationWithKey(pH, key)
XR_CLProcsHandle pH;
char *key;
{
XR_CLRegistrationInner ans;
if( pH == NIL ) return NIL;
LOCK();
ans = XR_CLLookupRegistrationInternal(pH, key, TRUE);
UNLOCK();
return ((XR_CLRegistration)(ans));
}
void
XR_CLEnumerateRegistrations(pH, eachRegistration)
XR_CLProcsHandle pH;
XR_MesaProc eachRegistration;
{
XR_CLRegistrationInner clr;
bool more;
if( pH == NIL )
return;
if( (eachRegistration == NIL) || (eachRegistration->mp_proc == NIL) )
return;
LOCK();
clr = ((XR_CLProcsHandleInner)(pH))->clph_registrations;
while( clr != NIL ) {
more = (bool) ( (*(eachRegistration->mp_proc))(
((XR_CLRegistration)(clr)), eachRegistration ) );
if( !more ) break;
clr = clr->clr_next;
}
UNLOCK();
}
void
XR_CLGetRegistrationDetails(r, key, caseSensitive, helpMsg, proc, clientData)
XR_CLRegistration r;
char **key;
bool *caseSensitive;
char **helpMsg;
XR_MesaProc *proc;
{
XR_CLRegistrationInner clr;
if( r == NIL ) return;
clr = ((XR_CLRegistrationInner)(r));
if( key != NIL ) *key = clr->clr_key;
if( caseSensitive != NIL ) *caseSensitive = clr->clr_caseSensitive;
if( helpMsg != NIL ) *helpMsg = clr->clr_helpMsg;
if( proc != NIL ) *proc = clr->clr_proc;
}
XR_MesaProc
XR_CLGetProcForKey(pH, key)
XR_CLProcsHandle pH;
char *key;
{
XR_CLRegistrationInner clr;
XR_MesaProc ans = NIL;
if( pH == NIL ) return NIL;
LOCK();
clr = XR_CLLookupRegistrationInternal(pH, key, TRUE);
if( (clr == NIL) && (key[0] == '-') )
clr = XR_CLLookupRegistrationInternal(pH, &(key[1]), TRUE);
if( clr != NIL ) ans = clr->clr_proc;
UNLOCK();
return ans;
}
void
XR_CLDestroyProcsHandle(pH)
XR_CLProcsHandle pH;
{
}
/*
* Argument parsing
*/
typedef unsigned XR_CLArgRes;
#define CL_ARG_RES_INL 1 /* inside-line */
#define CL_ARG_RES_EOL 2 /* end-of-line */
#define CL_ARG_RES_EOF 3 /* end-of-file */
#define CL_ARG_RES_ERR 4 /* error */
static void
XR_CLDoPrompt(clh)
XR_CLHandleInner clh;
{
XR_MesaProc promptSelf;
XR_UntypedProc promptProc;
char promptBuf[20];
if( ((promptSelf = clh->clh_promptProc) != NIL)
&& ((promptProc = promptSelf->mp_proc) != NIL) ) {
(void) XR_SPrintF( promptBuf,
((clh->clh_nestLevel > 0) ? "pcr(%d): " : "pcr: "),
clh->clh_nestLevel );
(void)( (*promptProc)( promptBuf, strlen(promptBuf), promptSelf ) );
}
}
static XR_CLArgRes
XR_CLReadArg(clh, buf, bufSize)
XR_CLHandleInner clh;
char *buf;
unsigned bufSize;
{
char *to;
char *endp;
int c;
XR_MesaProc self;
XR_UntypedProc proc;
if( ((self = clh->clh_charProc) == NIL)
|| ((proc = self->mp_proc) == NIL) )
return CL_ARG_RES_EOF;
# define GETCHAR() ((int)( (*proc)(self) ))
if( bufSize == 0 ) XR_Panic("CLReadArg 0");
to = buf;
endp = buf+bufSize-1;
c = clh->clh_peekc;
/* scan to beginning of token */
for(;;) {
if( c <= 0 ) { clh->clh_peekc = c; return CL_ARG_RES_EOF; }
if( c == '\n' ) {
XR_CLDoPrompt(clh);
if( (c = GETCHAR()) == '#' ) {
/* comment */
while( (c = GETCHAR()) != '\n' ) {
if( c <= 0 ) { clh->clh_peekc = c; return CL_ARG_RES_EOF; }
}
}
continue;
}
if( isspace(c) ) {
c = GETCHAR();
continue;
}
if( c == '\\' ) {
c = GETCHAR();
if( c <= 0 ) { clh->clh_peekc = c; return CL_ARG_RES_EOF; }
if( isspace(c) ) { c = ' '; continue; }
break;
}
break;
}
/* copy token to output buffer */
*to = c; if( to < endp ) to++;
c = ( (c == '@') ? ' ' : (GETCHAR()) ); /* KLUDGE for "-@filename" */
for(;;) {
if( (c <= 0) || isspace(c) ) break;
if( c == '\\' ) {
c = GETCHAR();
if( c <= 0 ) break;
}
*to = c; if( to < endp ) to++;
c = GETCHAR();
}
*to = 0;
/* check for eof/eol */
for(;;) {
clh->clh_peekc = c;
if( c <= 0 ) return CL_ARG_RES_EOL;
/* n.b. peekc will catch EOF on next call */
if( c == '\n' ) return CL_ARG_RES_EOL;
if( !isspace(c) ) return CL_ARG_RES_INL;
c = GETCHAR();
}
}
#undef GETCHAR
#define CL_INITIAL_ARGC_LIM 8
static int
XR_CLGrowHandle(clh, howMuch)
XR_CLHandleInner clh;
unsigned howMuch; /* 0 ==> default */
{
unsigned newArgcLim;
char **newArgv;
if( clh == NIL ) return (-1);
if( howMuch == 0 ) {
howMuch = clh->clh_argcLim;
if( howMuch == 0 ) howMuch = CL_INITIAL_ARGC_LIM;
}
newArgcLim = clh->clh_argcLim + howMuch;
newArgv = (char **) XR_CLNew(newArgcLim * sizeof(char *));
if( newArgv == NIL ) return (-1);
if( clh->clh_argv != NIL ) {
bcopy(clh->clh_argv, newArgv, clh->clh_argcLim*sizeof(char *));
}
clh->clh_argv = newArgv;
clh->clh_argcLim = newArgcLim;
return 0;
}
#define CL_WORD_BUF_SIZE 256
static XR_CLArgRes
XR_CLMakeArgAvailable(clh, argno)
XR_CLHandleInner clh;
int argno;
{
XR_CLArgRes ans;
char *nextArg;
char wordBuf[CL_WORD_BUF_SIZE];
if( argno < 0 ) XR_Panic("CLMakeArgAvailable 0");
if( argno < clh->clh_argc ) return CL_ARG_RES_INL;
ans = XR_CLReadArg(clh, wordBuf, (sizeof wordBuf));
switch( ans ) {
case CL_ARG_RES_INL:
case CL_ARG_RES_EOL:
nextArg = (char *) XR_CLNew(1+strlen(wordBuf));
(void) strcpy(nextArg, wordBuf);
if( clh->clh_argc >= clh->clh_argcLim ) XR_CLGrowHandle(clh, 0);
clh->clh_argv[clh->clh_argc] = nextArg;
clh->clh_argc += 1;
break;
case CL_ARG_RES_EOF:
break;
default:
XR_Panic("CLMakeArgAvailable 1");
}
return ans;
}
XR_CLHandle
XR_CLCreateHandleFromCharProc(charProc, promptProc)
XR_MesaProc charProc;
XR_MesaProc promptProc;
{
XR_CLHandleInner clh;
clh = ((XR_CLHandleInner)(XR_CLNew(sizeof *clh)));
clh->clh_charProc = charProc;
clh->clh_peekc = '\n';
clh->clh_promptProc = promptProc;
return ((XR_CLHandle)(clh));
}
typedef struct XR_CLFileInfoRep {
XR_Fildes clfi_promptFildes;
XR_Fildes clfi_fildes;
bool clfi_eof;
unsigned clfi_pos;
unsigned clfi_lim;
char clfi_buf[256];
} * XR_CLFileInfo;
static int
XR_CLBufferedCharProcForFile(self)
XR_MesaProc self;
{
int ans;
XR_CLFileInfo clfi = ((XR_CLFileInfo)(self->mp_x));
if( clfi->clfi_pos >= clfi->clfi_lim ) {
if( !(clfi->clfi_eof) ) {
ans = XR_Read(clfi->clfi_fildes, clfi->clfi_buf,
(sizeof (clfi->clfi_buf)) );
if( ans > 0 ) {
clfi->clfi_pos = 0;
clfi->clfi_lim = ans;
} else {
clfi->clfi_eof = TRUE;
}
}
if( clfi->clfi_eof ) return (-1);
}
ans = clfi->clfi_buf[clfi->clfi_pos];
clfi->clfi_pos += 1;
return ans;
}
static int
XR_CLUnbufferedCharProcForFile(self)
XR_MesaProc self;
{
XR_CLFileInfo clfi = ((XR_CLFileInfo)(self->mp_x));
int ans;
if( !clfi->clfi_eof ) {
ans = XR_Read(clfi->clfi_fildes, clfi->clfi_buf, 1);
clfi->clfi_eof = (ans <= 0);
}
return ((clfi->clfi_eof) ? (-1) : clfi->clfi_buf[0]);
}
static void
XR_CLPromptProcForFile(buf, nBytes, self)
char *buf;
int nBytes;
XR_MesaProc self;
{
XR_CLFileInfo clfi = ((XR_CLFileInfo)(self->mp_x));
if( clfi->clfi_promptFildes != XR_nullFildes ) {
(void) XR_Write( clfi->clfi_promptFildes, buf, nBytes );
}
}
XR_CLHandle
XR_CLCreateHandleFromFile(fd, fdPrompt)
XR_Fildes fd, fdPrompt;
{
XR_CLFileInfo clfi;
XR_UntypedProc theCharProc, thePromptProc;
XR_CLHandle h;
if( fd == XR_nullFildes ) return NIL;
clfi = (XR_CLFileInfo) XR_CLNew( sizeof *clfi );
if( clfi == NIL ) return NIL;
clfi->clfi_promptFildes = fdPrompt;
clfi->clfi_fildes = fd;
if( fdPrompt == XR_nullFildes ) {
theCharProc = ((XR_UntypedProc)(XR_CLBufferedCharProcForFile));
thePromptProc = NIL;
} else {
theCharProc = ((XR_UntypedProc)(XR_CLUnbufferedCharProcForFile));
thePromptProc = ((XR_UntypedProc)(XR_CLPromptProcForFile));
}
h = XR_CLCreateHandleFromCharProc(
XR_MakeMesaProc(
theCharProc, ((XR_Pointer)(clfi))
),
XR_MakeMesaProc(
thePromptProc, ((XR_Pointer)(clfi))
)
);
return h;
}
typedef struct XR_CLStringInfoRep {
char *clsi_buf;
char *clsi_next;
} * XR_CLStringInfo;
static int
XR_CLCharProcForString(self)
XR_MesaProc self;
{
XR_CLStringInfo clsi = ((XR_CLStringInfo)(self->mp_x));
int ans;
if( clsi == NIL ) return (-1);
if( clsi->clsi_next == NIL ) return (-1);
ans = ((int)(*(clsi->clsi_next)));
if( ans == 0 ) return (-1);
clsi->clsi_next += 1;
return ans;
}
XR_CLHandle
XR_CLCreateHandleFromString(string)
char *string;
{
char *s;
XR_CLStringInfo clsi;
XR_CLHandle h;
s = (char *)XR_CLNew(1+strlen(string));
if( s == NIL ) return NIL;
strcpy(s, string);
clsi = (XR_CLStringInfo) XR_CLNew( sizeof (*clsi) );
if( clsi == NIL ) return NIL;
clsi->clsi_next = clsi->clsi_buf = s;
h = XR_CLCreateHandleFromCharProc(
XR_MakeMesaProc(
(XR_UntypedProc)XR_CLCharProcForString, ((XR_Pointer)(clsi))
),
NIL
);
if( h != NIL ) {
((XR_CLHandleInner)(h))->clh_minusIsDelim = TRUE;
}
return h;
}
XR_CLHandle
XR_CLCreateHandleFromArgs(argc, argv)
int argc;
char **argv;
{
XR_CLHandleInner clh;
char *newLineFlags = NIL;
int i;
clh = ((XR_CLHandleInner)(XR_CLNew(sizeof *clh)));
if( clh == NIL ) return NIL;
clh->clh_minusIsDelim = TRUE;
clh->clh_argc = argc;
clh->clh_argcLim = argc;
clh->clh_argv = argv;
return ((XR_CLHandle)(clh));
}
int
XR_CLPrependArgsToHandle(h, argc, argv)
XR_CLHandle h;
int argc;
char **argv;
{
XR_CLHandleInner clh;
int i, ans, new_argc;
if( h == NIL ) return (-1);
if( argc == 0 ) return 0;
if( argv == NIL ) return (-1);
clh = ((XR_CLHandleInner)(h));
LOCKHANDLE(clh);
new_argc = argc + clh->clh_argc;
if( clh->clh_argcLim < new_argc ) {
ans = XR_CLGrowHandle(clh, argc + (new_argc / 4));
if( ans < 0 ) {
UNLOCKHANDLE(clh);
return (-1);
}
}
for( i = clh->clh_argc - 1; i >= 0; i-- ) {
clh->clh_argv[i+argc] = clh->clh_argv[i];
}
for( i = 0; i < argc; i++ ) {
clh->clh_argv[i] = argv[i];
}
clh->clh_argc = new_argc;
UNLOCKHANDLE(clh);
return 0;
}
void
XR_CLDestroyHandle(h)
XR_CLHandle h;
{
}
static int
XR_CLGetArgGroup(clh, start)
XR_CLHandleInner clh;
int start;
{
int i, len;
XR_CLArgRes ans;
char *arg;
for( i = start; ; i++ ) {
ans = XR_CLMakeArgAvailable(clh, i);
switch( ans ) {
case CL_ARG_RES_INL:
case CL_ARG_RES_EOL:
arg = clh->clh_argv[i];
if( arg[0] == '[' ) {
clh->clh_nestLevel += 1;
}
if( (arg[0] == '-') && (i > start)
&& clh->clh_minusIsDelim
&& (clh->clh_nestLevel == 0) ) {
return (i - start);
}
if( clh->clh_nestLevel > 0) {
len = strlen(arg);
if( (len > 0) && (arg[len-1] == ']') )
clh->clh_nestLevel -= 1;
}
if( (ans == CL_ARG_RES_EOL) && (clh->clh_nestLevel == 0) )
return (i - start + 1);
continue;
case CL_ARG_RES_EOF:
return (i - start);
default:
XR_Panic("CLGetArgGroup 0");
}
}
}
int
XR_CLApply(clce, preProc, postProc)
XR_CLCallEnv clce;
XR_MesaProc preProc;
XR_MesaProc postProc;
{
XR_CLProcsHandleInner clph;
XR_CLHandleInner clh;
int start, i, argc;
XR_CLProc fixedPreProc, fixedPostProc;
XR_MesaProc handlerProc;
int (*fixedHandlerProc)(/* int prevResult, XR_MesaProc self */);
int ans = 1;
# define totalFailure 0x80000000
if( clce == NIL ) return (totalFailure);
clph = ((XR_CLProcsHandleInner)(clce->clce_pH));
if( clph == NIL ) return (totalFailure);
clh = ((XR_CLHandleInner)(clce->clce_h));
if( clh == NIL ) return (totalFailure);
fixedPreProc =
((preProc == NIL) ? NIL : ((XR_CLProc)(preProc->mp_proc)));
fixedPostProc =
((postProc == NIL) ? NIL : ((XR_CLProc)(postProc->mp_proc)));
LOCKHANDLE(clh);
for( ((start = 0), (i = 0)); TRUE; ((start += argc), (i += 1)) ) {
argc = XR_CLGetArgGroup(clh, start);
if( argc <= 0 ) break;
{
XR_MesaProc proc;
XR_CLProc fixedProc;
int preProcResult, procResult, postProcResult;
int setjmpAns;
/* invoke preProc */
preProcResult = 0;
if( fixedPreProc != NIL ) {
preProcResult = (*fixedPreProc)(
clce, argc, clh->clh_argv+start, 0, preProc );
}
if( preProcResult > 0 ) continue;
if( preProcResult < 0 ) break;
/* get and invoke registered CLProc */
procResult = 0;
proc = XR_CLGetProcForKey(
(XR_CLProcsHandle)(clce->clce_pH),
&((clh->clh_argv[start])[0]) );
if( proc != NIL ) {
fixedProc = ((XR_CLProc)(proc->mp_proc));
setjmpAns = XR_setjmp(&(clce->clce_jmpBuf));
if( setjmpAns == 0 ) {
procResult = (*fixedProc)(
clce, argc, clh->clh_argv+start, 0, proc );
} else /* proc aborted by longjmp */ {
procResult = setjmpAns;
}
}
/* invoke postProc */
postProcResult = 1;
if( fixedPostProc != NIL ) {
postProcResult = (*fixedPostProc)(
clce, argc, clh->clh_argv+start, procResult, postProc );
}
if( (ans = postProcResult) <= 0 ) {
handlerProc = clce->clce_handlerProc;
fixedHandlerProc =
((handlerProc == NIL)
? NIL
: ((XR_CLProc)(handlerProc->mp_proc)));
if( fixedHandlerProc != NIL ) {
ans = (*fixedHandlerProc)(procResult, handlerProc);
}
if( ans <= 0 ) break;
}
}
}
UNLOCKHANDLE(clh);
return ans;
}
int
XR_CLCallIndirect(clce, key, argc, argv)
XR_CLCallEnv clce;
char *key;
int argc;
char **argv;
{
XR_MesaProc proc;
int ans;
struct XR_JmpBufRep prevJmpBuf;
proc = XR_CLGetProcForKey( (XR_CLProcsHandle)(clce->clce_pH), key );
if( proc == NIL ) {
XR_CLErrorMsg "%s: %s not found\n",
((argc > 0) ? argv[0] : key), key );
return (-1);
}
(void) bcopy(&(clce->clce_jmpBuf), &prevJmpBuf, (sizeof prevJmpBuf));
if( (ans = XR_setjmp(&(clce->clce_jmpBuf))) == 0 ) {
ans = (int)( (*(proc->mp_proc)) (
clce, argc, argv, 0, proc) );
}
(void) bcopy(&prevJmpBuf, &(clce->clce_jmpBuf), (sizeof prevJmpBuf));
return ans;
}
/*
*
* Utilities
*
*/
XR_CLPROC(XR_CLProc_setBool)
{
bool isOn, wasOn;
XR_CLSetBoolProc onOffProc;
switch( argc ) {
case 2:
if( (strcmp(argv[1], "on") == 0)
|| (strcmp(argv[1], "true") == 0)
|| (strcmp(argv[1], "ON") == 0)
|| (strcmp(argv[1], "TRUE") == 0) ) {
isOn = TRUE;
break;
}
if( (strcmp(argv[1], "off") == 0)
|| (strcmp(argv[1], "false") == 0)
|| (strcmp(argv[1], "OFF") == 0)
|| (strcmp(argv[1], "FALSE") == 0) ) {
isOn = FALSE;
break;
}
default:
XR_CLErrorMsg "%s args: [on|off]\n", argv[0]);
return (-1);
}
onOffProc = (XR_CLSetBoolProc)(self->mp_x);
wasOn = (*onOffProc)(isOn);
XR_CLNormalMsg "%s set %s (was %s)\n",
argv[0], (isOn ? "on" : "off"), (wasOn ? "on" : "off") );
return 1;
}
XR_CLPROC(XR_CLProc_setUnsigned)
{
unsigned newNum, oldNum;
XR_CLSetUnsignedProc numberProc;
switch( argc ) {
case 2:
newNum = atol(argv[1]);
break;
default:
XR_CLErrorMsg "%s args: number\n", argv[0]);
return (-1);
}
numberProc = (XR_CLSetUnsignedProc)(self->mp_x);
oldNum = (*numberProc)(newNum);
XR_CLNormalMsg "%s set to %d (was %d)\n", argv[0], newNum, oldNum );
return 1;
}
#ifdef UNDEFINED
/*
* DEBUGGING PROCS
*/
XR_CLHandle
XR_CLDBCreate(argc, argv0, argv1, argv2, argv3, argv4, argv5, argv6, argv7)
int argc;
char *argv0;
char *argv1;
char *argv2;
char *argv3;
char *argv4;
char *argv5;
char *argv6;
char *argv7;
{
char **argv;
if( (argc <= 0) || (argc > 8) ) return NIL;
argv = (char **)(XR_malloc(argc*sizeof(char *)));
if( argc > 0 ) argv[0] = argv0;
if( argc > 1 ) argv[1] = argv1;
if( argc > 2 ) argv[2] = argv2;
if( argc > 3 ) argv[3] = argv3;
if( argc > 4 ) argv[4] = argv4;
if( argc > 5 ) argv[5] = argv5;
if( argc > 6 ) argv[6] = argv6;
if( argc > 7 ) argv[7] = argv7;
return XR_CLCreateHandleFromArgs(argc, argv, NIL);
}
#define MSG XR_Msg(XR_MSG_STDOUT,
XR_CLPROC(XR_CLDBProc)
{
int i;
MSG "CLDBProc_%s called: pr %d which %d clce 0x%x args ",
prevResult, which, clce, self->mp_x);
for( i = 0; i < argc; i++ ) {
MSG "%s ", argv[i]);
}
return 1;
}
struct XR_MesaProcRep XR_CLDBMProc_preProc = {
(XR_UntypedProc)(XR_CLDBProc), (XR_Pointer)("preProc") };
struct XR_MesaProcRep XR_CLDBMProc_postProc = {
(XR_UntypedProc)(XR_CLDBProc), (XR_Pointer)("postProc") };
struct XR_MesaProcRep XR_CLDBMProc_regProc = {
(XR_UntypedProc)(XR_CLDBProc), (XR_Pointer)("regProc") };
int
XR_CLDBReadFile(fileName, pH, msgSink, verbosity, preProc, postProc)
char *fileName;
XR_CLProcsHandle pH;
XR_MesaProc msgSink;
int verbosity;
XR_MesaProc preProc;
XR_MesaProc postProc;
{
XR_Fildes fd;
struct XR_CLCallEnvRep clce;
XR_CLHandle h;
int ans;
int localVerbosity = verbosity;
fd = XR_Open(fileName, O_RDONLY, 0);
if( fd == XR_nullFildes ) return (-1);
(void) XR_SetGetBlocking(fd, XR_UIO_BLOCKING_SOME_DATA); /* default */
h = XR_CLCreateHandleFromFile(fd);
clce.clce_h = h;
clce.clce_pH = pH;
clce.clce_msgSink = msgSink;
clce.clce_msgVerbosityP = &localVerbosity;
clce.clce_handlerProc = NIL;
clce.clce_clientData = NIL;
ans = XR_CLApply( &clce, preProc, postProc );
(void) XR_Close(fd);
return ans;
}
#endif UNDEFINED
XR_PrintArgV(argv, start, limit)
char **argv;
int start, limit;
{
while( start < limit ) {
XR_ConsoleMsg(" %d: %s\n", start, argv[start]);
XR_SpinStep(50000);
start += 1;
}
}